
export const desc = {
    "name": "选择角色进入游戏",
    "desc": "直接传角色id",
    "params_type": "角色id",
    "params": [],
    "returns": [],
    "example": 'JGESDK:发送(4,1)'
}
// @ts-ignore
export async function execute(client_id, characters_id) {
    if (typeof characters_id !== "number") {
        ClientUtils.send_basic_prompt(client_id, "#R非法请求");
        return;
    }
    let characters = G.Characters.master_login(client_id, _ClientUserNameData.get(client_id), characters_id);

    if (characters === undefined) {
        ClientUtils.send_basic_prompt(client_id, "#Y/角色不存在");
    } else {
        //发送登录信息
        G.Characters.send_login_characters_data(client_id, characters);
        // 判断是否在队伍中
        if (characters["队伍"] !== 0) {
            let team_data = G.TeamUtils.get_team_data(characters["队伍"]);
            let characters_id = characters["id"];
            if (team_data === undefined) {
                //队伍数据丢失
                ClientUtils.send_client_message(client_id, 4008, 1);
                characters["队伍"] = 0;
                characters["队长"] = false;
                G.MapUtils.update_team_icon(characters_id, false);
            } else {
                let send_data = G.TeamUtils.build_send_team_data(characters["队伍"]);
                ClientUtils.send_client_message(client_id, 4002, send_data);
                if (characters["队长"]) {
                    ClientUtils.send_client_message(client_id, 4006, 1);
                    G.MapUtils.update_team_icon(characters_id, true);
                } else {
                    ClientUtils.send_client_message(client_id, 4008, 1);
                    G.MapUtils.update_team_icon(characters_id, true);
                }
                G.TeamUtils.send_team_message(characters["队伍"], `成员#Y[${characters["名称"]}]#G进入游戏`);
            }
        }
        // 战斗中则重新加入战斗
        if (characters["战斗开关"] !== 0) {
            let fight_data = _FightDataCache.get(characters["战斗开关"]);
            if (fight_data) {
                // 重连回来以后取消自动战斗
                let fight_unit = G.FightUtils.get_fight_unit_by_characters(fight_data, characters);
                fight_unit["自动战斗"] = false;
                G.MapUtils.update_fight_icon(characters, true);
                let client_fight_data = G.FightUtils.build_client_fight_data(fight_data);
                G.FightUtils.send_join_fight_data(client_id, client_fight_data[0], client_fight_data[1]);
                ClientUtils.send_basic_prompt(client_id, "#你已重新加入战斗,请等待本回合完成");
            } else {
                characters["战斗开关"] = 0;
                G.MapUtils.update_fight_icon(characters, false);
            }
        }

        G.ChatUtils.send_system_chat(client_id, `#G${characters["名称"]},#Y欢迎进入JS端测试服,聊天内输入 #R@帮助 #Y可查看GM命令`);
        // // 测试性能 玩家进入游戏后 向该地图内添加一万个玩家
        // let x = 250;
        // let y = 150;
        // for (let index = 1; index < 101; index++) {
        //     let random = generate_random_number(1.10);
        //     if(random > 5){
        //         characters["地图数据"]["x"]=x+generate_random_number(5,30);
        //         characters["地图数据"]["y"]=y+generate_random_number(5,30);
        //     }else{
        //         characters["地图数据"]["x"]=x-generate_random_number(10,50);
        //         characters["地图数据"]["y"]=y-generate_random_number(10,50);
        //     }
        //     characters["名称"]="测试玩家"+index;
        //     characters["id"]=Number(characters["id"])+1;
        //     await G.MapUtils.add_characters(characters["地图数据"]["编号"],characters);
        // }
    }
}


